package com.zy.mq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.jms.*;

@Service
public class ActiveMQProducer {

    private final Logger log= LoggerFactory.getLogger(ActiveMQProducer.class);

    @Resource
    private JmsTemplate jmsTemplate;


    public void send(final String  message){
        jmsTemplate.send(new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                TextMessage textMessage = session.createTextMessage(message);
               log.info("发送消息："+textMessage);
                return  textMessage;
            }
        });
    }
}
